package cse326.fuellog;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import android.app.Activity;

public class AddVehicle extends Activity
{

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_add_vehicle);
	}

	public void addVehicle(View view)
	{
		// First, validate the form.

		EditText year = (EditText)findViewById(R.id.addvehicle_year);
		EditText make = (EditText)findViewById(R.id.addvehicle_make);
		EditText model = (EditText)findViewById(R.id.addvehicle_model);
		EditText color = (EditText)findViewById(R.id.addvehicle_color);

		if (year.getText().toString().length() == 0)
		{
			Toast.makeText(getApplicationContext(),"Need to enter the year.",Toast.LENGTH_SHORT).show();
			return;
		}
		if (make.getText().toString().length() == 0)
		{
			Toast.makeText(getApplicationContext(),"Need to enter the manufacturer.",Toast.LENGTH_SHORT).show();
			return;
		}
		if (model.getText().toString().length() == 0)
		{
			Toast.makeText(getApplicationContext(),"Need to enter the model.",Toast.LENGTH_SHORT).show();
			return;
		}
		if (color.getText().toString().length() == 0)
		{
			Toast.makeText(getApplicationContext(),"Need to enter the color.",Toast.LENGTH_SHORT).show();
			return;
		}

		Vehicle v = new Vehicle();
		v.setDB(MainActivity.db);
		v.setColor(color.getText().toString().trim());
		v.setMake(make.getText().toString().trim());
		v.setModel(model.getText().toString().trim());
		v.setYear(Integer.parseInt(year.getText().toString().trim()));

		v.addToDB();

		Toast.makeText(getApplicationContext(),"Added successfully.",Toast.LENGTH_LONG).show();

		finish();

	}

}
